package com.stropheware.pathfinding;

import java.util.ArrayList;
import java.util.Collections;


/**
 * A simple sorted list
 *
 * @author kevin
 * edited by paulgagliardi
 */
public class SortedList {
	/** The list of elements */
	private ArrayList<Node> list = new ArrayList<Node>();
	
	
	/**
	 * Retrieve the first element from the list
	 *  
	 * @return The first element from the list
	 */
	public Node first() {
		return list.get(0);
	}
	
	/**
	 * Empty the list
	 */
	public void clear() {
		list.clear();
	}
	
	/**
	 * Add an element to the list - causes sorting
	 * 
	 * @param o The element to add
	 */
	public void add(Node n) {
		list.add(n);
		Collections.sort(list);
	}
	
	/**
	 * Remove an element from the list
	 * 
	 * @param o The element to remove
	 */
	public void remove(Node n) {
		list.remove(n);
	}

	/**
	 * Get the number of elements in the list
	 * 
	 * @return The number of element in the list
		 */
	public int size() {
		return list.size();
	}
	
	/**
	 * Check if an element is in the list
	 * 
	 * @param o The element to search for
	 * @return True if the element is in the list
	 */
	public boolean contains(Node n) {
		return list.contains(n);
	}
}